package org.tlipoca.smsteamstore.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.tlipoca.smsteamstore.properties.ElasticSearchProperties;

@Configuration
public class ElasticSearchConfig {

    @Bean(destroyMethod = "close")
    @ConditionalOnMissingBean
    public RestHighLevelClient client(ElasticSearchProperties elasticSearchProperties){
        System.out.println(elasticSearchProperties.getHost()+elasticSearchProperties.getPort());
        return new RestHighLevelClient(RestClient.builder(
                new HttpHost(elasticSearchProperties.getHost(), elasticSearchProperties.getPort(),"http")
        ));
    }

}
